'''
Created on Oct 11, 2012

@author: daeheehan
'''
import sys
import os

from github import Github
from github import Issue
from github import IssueEvent

# Github User information
GITHUB_USER_ID = "booknara"
GITHUB_USER_ID_1 = "booknaratest"
GITHUB_USER_ID_2 = "jangho87"

GITHUB_USER_PW = "qwer1234"

if __name__ == '__main__':
    pass

g = Github(GITHUB_USER_ID_1, GITHUB_USER_PW)
print str(g.rate_limiting) + ' request remaining'

# Github Bootstrap Repository information
GITHUB_BOOTSTRAP_ORG_NAME = "twitter"
GITHUB_BOOTSTRAP_REPOSITORY_NAME = "bootstrap"

## This part is for getting bootstrap collaborators
user = g.get_user(GITHUB_BOOTSTRAP_ORG_NAME)
repo = user.get_repo(GITHUB_BOOTSTRAP_REPOSITORY_NAME)

collaborators_list = []
contributors_list = []
try:
    bootstrap_collaborators = open('bootstrap_collaborators.txt', 'w')

    for name in repo.get_collaborators():
        sys.stdout.write('.')
#        bootstrap_collaborators.write('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
        collaborators_list.append('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
#        print 'Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location)
    
    for item in collaborators_list:
        bootstrap_collaborators.write('%s\n' % item)
    print '------------------------------'
    bootstrap_collaborators.close()

    bootstrap_contributors = open('bootstrap_contributors.txt', 'w')
    for name in repo.get_contributors():
        sys.stdout.write('.')
        bootstrap_contributors.write('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
#        print 'Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location)
    contributors_list.append(object)
    print '------------------------------'
    bootstrap_contributors.close()

except IOError:
    print('File Error')

print 'bootstrap_collaborators/bootstrap_contributors the end'

# It's a time to sleep for 1 hour
time.sleep(60 * 60)

GITHUB_HOMEBREW_USER_NAME = "mxcl"
GITHUB_HOMEBREW_REPOSITORY_NAME = "homebrew"

## This part is for getting bootstrap collaborators
user = g.get_user(GITHUB_HOMEBREW_USER_NAME)
repo = user.get_repo(GITHUB_HOMEBREW_REPOSITORY_NAME)

collaborators_list = []
contributors_list = []
try:
    homebrew_collaborators = open('homebrew_collaborators.txt', 'w')

    for name in repo.get_collaborators():
        sys.stdout.write('.')
        collaborators_list.append('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
#        print 'Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location)
    print '------------------------------'
    
    for item in collaborators_list:
        homebrew_collaborators.write('%s' % item)
    homebrew_collaborators.close()
    print '------------------------------'

    homebrew_contributors = open('homebrew_contributors.txt', 'w')
    for name in repo.get_contributors():
        sys.stdout.write('.')
        contributors_list.append('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
#        print 'Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location)
    print '------------------------------'
    
    for item in contributors_list:
        homebrew_contributors.write('%s' % item)
    homebrew_contributors.close()
    print '------------------------------'

except Exception  as inst: 
    print inst

print 'homebrew_collaborators/homebrew_contributors the end'

# Github Rails Repository information
GITHUB_RAILS_ORG_NAME = "rails"
GITHUB_RAILS_REPOSITORY_NAME = "rails"

## This part is for getting bootstrap collaborators
user = g.get_user(GITHUB_RAILS_ORG_NAME)
repo = user.get_repo(GITHUB_RAILS_REPOSITORY_NAME)

collaborators_list = []
contributors_list = []
try:
    rails_collaborators = open('rails_collaborators.txt', 'w')
    
    for name in repo.get_collaborators():
        sys.stdout.write('.')
        collaborators_list.append('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
#        print 'Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location)
    print '------------------------------'
    
    for item in collaborators_list:
        rails_collaborators.write('%s' % item)
    rails_collaborators.close()
    print '------------------------------'

    rails_contributors = open('rails_contributors.txt', 'w')
    for name in repo.get_contributors():
        sys.stdout.write('.')
        contributors_list.append('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
#        print 'Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location)
    print '------------------------------'
    
    for item in contributors_list:
        rails_contributors.write('%s' % item)
    rails_contributors.close()
    print '------------------------------'

except Exception  as inst: 
    print inst

print 'rails_collaborators/rails_contributors the end'

# It's a time to sleep for 1 hour
time.sleep(60 * 60)

# Github html5 boilerplate Repository information
GITHUB_H5BP_ORG_NAME = "h5bp"
GITHUB_HTML5_BOILERPLATE_REPOSITORY_NAME = "html5-boilerplate"

## This part is for getting bootstrap collaborators
user = g.get_user(GITHUB_H5BP_ORG_NAME)
repo = user.get_repo(GITHUB_HTML5_BOILERPLATE_REPOSITORY_NAME)

collaborators_list = []
contributors_list = []
try:
    html5_boilerplate_collaborators = open('html5_boilerplate_collaborators.txt', 'w')

    for name in repo.get_collaborators():
        sys.stdout.write('.')
        collaborators_list.append('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
    print '------------------------------'
    
    for item in collaborators_list:
        html5_boilerplate_collaborators.write('%s' % item)
    html5_boilerplate_collaborators.close()
    print '------------------------------'

    html5_boilerplate_contributors = open('html5_boilerplate_contributors.txt', 'w')    
    for name in repo.get_contributors():
        sys.stdout.write('.')
        html5_boilerplate_contributors.write('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
#        print 'Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location)
    print '------------------------------'

    for item in contributors_list:
        html5_boilerplate_contributors.write('%s' % item)
    html5_boilerplate_contributors.close()
    print '------------------------------'

except Exception  as inst: 
    print inst

print 'html5_boilerplate_collaborators/html5_boilerplate_contributors the end'

# Github oh-my-zsh Repository information
GITHUB_ROBBYRUSSELL_ORG_NAME = "robbyrussell"
GITHUB_OH_MY_ZSH_REPOSITORY_NAME = "oh-my-zsh"

## This part is for getting bootstrap collaborators
user = g.get_user(GITHUB_ROBBYRUSSELL_ORG_NAME)
repo = user.get_repo(GITHUB_OH_MY_ZSH_REPOSITORY_NAME)

collaborators_list = []
contributors_list = []
try:
    oh_my_zsh_collaborators = open('oh_my_zsh_collaborators.txt', 'w')
    for name in repo.get_collaborators():
        sys.stdout.write('.')
        oh_my_zsh_collaborators.write('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
    print '------------------------------'
    oh_my_zsh_collaborators.close()
    
    oh_my_zsh_contributors = open('oh_my_zsh_contributors.txt', 'w')    
    for name in repo.get_contributors():
        sys.stdout.write('.')
        oh_my_zsh_contributors.write('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
#        print 'Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location)
    print '------------------------------'
    oh_my_zsh_contributors.close()
    
except Exception  as inst: 
    print inst

print 'oh_my_zsh_collaborators/oh_my_zsh_contributors the end'


# It's a time to sleep for 1 hour
time.sleep(60 * 60)

# Github node Repository information
GITHUB_JOYENT_ORG_NAME = "joyent"
GITHUB_NODE_REPOSITORY_NAME = "node"

## This part is for getting node collaborators
user = g.get_user(GITHUB_JOYENT_ORG_NAME)
repo = user.get_repo(GITHUB_NODE_REPOSITORY_NAME)

collaborators_list = []
contributors_list = []
try:
    node_collaborators = open('node_collaborators.txt', 'w')

    for name in repo.get_collaborators():
        sys.stdout.write('.')
        node_collaborators.write('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
    print '------------------------------'
    node_collaborators.close()
    
    node_contributors = open('node_contributors.txt', 'w')
    for name in repo.get_contributors():
        sys.stdout.write('.')
        node_contributors.write('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
#        print 'Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location)
    print '------------------------------'
    node_contributors.close()
    
except Exception  as inst: 
    print inst

print 'node_collaborators/node_contributors the end'

# Github jquery Repository information
GITHUB_JQUERY_ORG_NAME = "jquery"
GITHUB_JQUERY_REPOSITORY_NAME = "jquery"

## This part is for getting jquery collaborators
user = g.get_user(GITHUB_JQUERY_ORG_NAME)
repo = user.get_repo(GITHUB_JQUERY_REPOSITORY_NAME)

collaborators_list = []
contributors_list = []
try:
    jquery_collaborators = open('jquery_collaborators.txt', 'w')
    for name in repo.get_collaborators():
        sys.stdout.write('.')
        jquery_collaborators.write('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
    print '------------------------------'
    jquery_collaborators.close()
    
    jquery_contributors = open('jquery_contributors.txt', 'w')
    for name in repo.get_contributors():
        sys.stdout.write('.')
        jquery_contributors.write('Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location) +'\n')
#        print 'Name: ' + str(name.name) + ', login: ' + str(name.login) + ', Location: ' + str(name.location)
    print '------------------------------'

    jquery_contributors.close()

except Exception as e: 
    print 'Exception: ' + str(e.args[0])

print 'jquery_collaborators/jquery_contributors the end'

print str(g.rate_limiting) + ' request remaining'
print 'Finally the end'
